local S = minetest.get_translator("default")

local function firstToUpper(str)
    return (str:gsub("^%l", string.upper))
end

-- For the new metals defined in this mod the craft recipes are registered
for _,metal in pairs(batteries.metalingots) do
    local metalname = firstToUpper(metal)

	technic.register_grinder_recipe({
		input = {"technic_batteries:"..metal.."_ingot"},
		output = "technic_batteries:"..metal.."_dust"
		})

	minetest.register_craft({
		type = "cooking",
		output = "technic_batteries:"..metal.."_ingot",
		recipe = "technic_batteries:"..metal.."_lump",
	})

	minetest.register_craft({
		type = "cooking",
		output = "technic_batteries:"..metal.."_ingot",
		recipe = "technic_batteries:"..metal.."_dust",
	})
	
end

-- In the first attempt the creation of acid is done by an own mechanism
for _,fruit in pairs(batteries.fruits) do
	minetest.register_craft({
		output = "technic_batteries:bucket_must_"..fruit[1],
		recipe = {{"technic_batteries:bottle_must_"..fruit[1],"technic_batteries:bottle_must_"..fruit[1]},
		{"technic_batteries:bottle_must_"..fruit[1],"technic_batteries:bottle_must_"..fruit[1]},}
	})
	minetest.register_craft({
		output = "technic_batteries:bottle_must_"..fruit[1],
		recipe = {{"technic_batteries:glass_must_"..fruit[1],"technic_batteries:glass_must_"..fruit[1]},
		{"technic_batteries:glass_must_"..fruit[1],"technic_batteries:glass_must_"..fruit[1]},}
	})

	minetest.register_craft({type = "shapeless",
		recipe = {"technic_batteries:bucket_must_"..fruit[1]},
		output = "technic_batteries:bottle_must_"..fruit[1].." 4",
	})
	minetest.register_craft({type = "shapeless",
		recipe = {"technic_batteries:bottle_must_"..fruit[1]},
		output = "technic_batteries:glass_must_"..fruit[1].." 4",
	})

	minetest.register_craft({
		type = "cooking",
		output = "technic_batteries:bucket_vinegar_"..fruit[1],
		recipe = "technic_batteries:bucket_must_"..fruit[1],
		cooktime=20,
	})
end

--[[
minetest.register_craftitem("technic_batteries:mv_battery", {
	description = S("Nickel Battery"),
	inventory_image = "batteries_batterie_mv.png",
})
minetest.register_craftitem("technic_batteries:hv_battery", {
	description = S("Lithium Battery"),
	inventory_image = "batteries_batterie_hv.png",
})
]]
minetest.register_craft({
	output = "technic_batteries:hv_battery",
	recipe = {
		{"basic_materials:plastic_strip",         "technic:sulfur_dust",   "basic_materials:plastic_strip"},
		{"technic_batteries:lithium_dust", "group:vinegar", "technic_batteries:lithium_dust"},
		{"basic_materials:plastic_strip",         "technic:sulfur_dust",   "basic_materials:plastic_strip"},
	},
	replacements = {
		{"group:vinegar", "bucket:bucket_empty"}
	}
})
minetest.register_craft({
	output = "technic_batteries:mv_battery",
	recipe = {
		{"mesecons_materials:fiber",         "technic:sulfur_dust",   "mesecons_materials:fiber"},
		{"technic_batteries:nickel_dust", "group:vinegar", "technic_batteries:nickel_dust"},
		{"mesecons_materials:fiber",         "technic:sulfur_dust",   "mesecons_materials:fiber"},
	},
	replacements = {
		{"group:vinegar", "bucket:bucket_empty"}
	}
})

minetest.register_craft({
	output = 'technic:mv_battery_box0',
	recipe = {
		{'basic_materials:steel_strip',  'basic_materials:steel_strip', 'basic_materials:steel_strip'},
		{'technic_batteries:mv_battery', 'technic:machine_casing',      'technic_batteries:mv_battery'},
		{'technic_batteries:mv_battery', 'technic:mv_cable',            'technic_batteries:mv_battery'},
	}
})

minetest.register_craft({
	output = 'technic:hv_battery_box0',
	recipe = {
		{'technic:carbon_plate',         'technic:composite_plate',  'technic:carbon_plate'},
		{'technic_batteries:hv_battery', 'technic:machine_casing',   'technic_batteries:hv_battery'},
		{'technic_batteries:hv_battery', 'technic:hv_cable',         'technic_batteries:hv_battery'},
	}
})


